There is the data: atp_tennis containing the following columns: ['Tournament', 'Date', 'Series', 'Court', 'Surface', 'Round', 'Best of', 'Player_1', 'Player_2', 'Winner', 'Rank_1', 'Rank_2', 'Pts_1', 'Pts_2', 'Odd_1', 'Odd_2', 'score'].  
--- The description for each column this data is:
Tournament: Name of the tennis tournament (Brisbane International, Chennai Open, Qatar Exxon Mobil Open ...etc)
Date: Date the match was played (year-month-day)
Series: Category or level of the tennis tournament (ATP250, ATP500, Masters1000 and Grand Slams offer 250, 500, 1000, and 2000 ranking points to the winner seperately.)
Court: Place the match was held (Indoors or Outdoors)
Surface: Type of court surface (Hard, Grass and Clay)
Round: Stage of the tournament (1st Round, 2nd Round, Quarterfinals, Semifinal and The Final)
Best of: Tourament systems ("best of 3" or "best of 5")
Player_1: Name of the first competitor in each match
Player_2: Name of the second competitor in each match
Winner: Name of the Player_1 or Player_2 who won the match 
Rank_1: World rankings of the Player_1 at the time of the match
Rank_2: World rankings of the Player_2 at the time of the match
Pts_1: Ranking points held by Player_1 before the match (accumulated over the season and higher points typically indicate a more successful player)
Pts_2: Ranking points held by Player_2 before the match
Odd_1: Betting odds for Player_1 (reflecting their perceived chances of winning)
Odd_2: Betting odds for Player_2 
Score: Final score of the match ("score of Player_1" - "score of Player_2")
---
Considering contents from the dataset and requirements from user. Please note DO NOT CHANGE FILE AND VARIABLE NAMES THAT I HAVE SET!
Interactions begin:
[USER (data scientist)]: Can you help me find the matches in the atp_tennis dataset where Roger Federer is either Player_1 or Player_2? I would like to have a list of Match IDs for these matches.

[YOU (AI assistant)]: Sure, I can help you with that. To find the matches where Roger Federer is either Player_1 or Player_2, you can use the following code :
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# Filter the DataFrame
federer_matches = atp_tennis[(atp_tennis['Player_1'] == 'Federer R.') | (atp_tennis['Player_2'] == 'Federer R.')]

# Convert the index to a list
federer_match_ids = federer_matches.index.tolist()

print(federer_match_ids)

'''

[USER (data scientist)]: Great! We have a new competitor named 'Raonic M.'. I need to find the win rates, head-to-head records against other players in the affected matches, and performance on the same surface as the tournament for this new competitor. Please provide a dataframe with Player Names, Win Rates, Head-to-Head Records, and Surface Performance.

[YOU (AI assistant)]: To find the win rates, head-to-head records, and surface performance for 'Raonic M.', you can use the following code :
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# Find Federer matches
federer_matches = atp_tennis[(atp_tennis['Player_1'] == 'Federer R.') | (atp_tennis['Player_2'] == 'Federer R.')]
federer_opponents = federer_matches['Player_1'].where(federer_matches['Player_1'] != 'Federer R.', federer_matches['Player_2']).unique()

# Retrieve unique surface types
surface_types = atp_tennis['Surface'].unique()

# Function to calculate a tennis player's overall win rate, head-to-head record, and performance on different surfaces against a specific opponent.
def calculate_performance(player, opponent, data, surface_types):
    player_matches = data[((data['Player_1'] == player) & (data['Player_2'] == opponent)) | ((data['Player_1'] == opponent) & (data['Player_2'] == player))]
    total_matches = len(player_matches)
    wins = len(player_matches[player_matches['Winner'] == player])
    win_rate = wins / total_matches if total_matches > 0 else 0

    h2h_record = wins / total_matches if total_matches > 0 else 0

    surface_performance = {}
    for surface in surface_types:
        player_surface_matches = player_matches[player_matches['Surface'] == surface]
        player_surface_wins = len(player_surface_matches[player_surface_matches['Winner'] == player])
        surface_performance[surface] = player_surface_wins / player_surface_matches.shape[0] if player_surface_matches.shape[0] > 0 else 0

    return win_rate, h2h_record, surface_performance

# Initialize an empty dataframe for storing the results
columns = ['Player', 'Opponent', 'Win Rate', 'Head-to-Head'] + [f'{surface} Surface Performance' for surface in surface_types]
player_stats = pd.DataFrame(columns=columns)

# Loop through Federer's opponents
for opponent in federer_opponents:
    # Calculate win rate, head-to-head record, and surface performance for Raonic M. against each opponent
    win_rate, h2h_record, surface_performance = calculate_performance('Raonic M.', opponent, atp_tennis, surface_types)

    # Append the results to the dataframe
    row_data = {'Player': 'Raonic M.', 'Opponent': opponent, 'Win Rate': win_rate, 'Head-to-Head': h2h_record}
    row_data.update({f'{surface} Surface Performance': surface_performance[surface] for surface in surface_types})
    player_stats = pd.concat([player_stats, pd.DataFrame(row_data, index=[0])], ignore_index=True)

# Display the resulting dataframe
print(player_stats)

'''

[USER (data scientist)]: Thank you. Now, I need to update the odds for each affected match, considering the new competitor's performance (win rate). Please provide a dataframe with Match IDs, Original Odds, and Updated Odds, where the odds are adjusted based on the new competitor's win rate and a performance weight factor.

My template of code snippet is:

---BEGIN CODE TEMPLATE---

import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
<code1>
[COMPLETE YOUR CODE] 
</code1>
# YOUR SOLUTION END

print(updated_odds_df)

# save data
pickle.dump(updated_odds_df,open("./pred_result/updated_odds_df.pkl","wb"))

---END CODE TEMPLATE---

Please note that you have to generate the WHOLE python code instead of code segments based on the code snippet using Pandas library 2.0.3 version and Matplotlib library 3.7.4 version. You must keep all comments in code snippet unchanged.

[YOU (AI assistant)]: To update the odds for each affected match, considering the new competitor's performance, you can use the following code:
'''
import pandas as pd
import numpy as np
import pickle

atp_tennis = pd.read_csv('atp_tennis.csv')

# YOUR SOLUTION BEGIN:
